home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / konq_undo.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  3.7 KB  |  163 lines

  1. /* This file is part of the KDE project
  2.    Copyright (C) 2000 Simon Hausmann <hausmann@kde.org>
  3.  
  4.    This library is free software; you can redistribute it and/or
  5.    modify it under the terms of the GNU Library General Public
  6.    License as published by the Free Software Foundation; either
  7.    version 2 of the License, or (at your option) any later version.
  8.  
  9.    This library is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.    Library General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU Library General Public License
  15.    along with this library; see the file COPYING.LIB.  If not, write to
  16.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.    Boston, MA 02110-1301, USA.
  18. */
  19. #ifndef __konq_undo_h__
  20. #define __konq_undo_h__
  21.  
  22. #include <qobject.h>
  23. #include <qstring.h>
  24. #include <qvaluestack.h>
  25.  
  26. #include <dcopobject.h>
  27.  
  28. #include <kurl.h>
  29. #include <libkonq_export.h>
  30.  
  31. namespace KIO
  32. {
  33.   class Job;
  34. }
  35.  
  36. class KonqUndoJob;
  37.  
  38. struct KonqBasicOperation
  39. {
  40.   typedef QValueStack<KonqBasicOperation> Stack;
  41.  
  42.   KonqBasicOperation()
  43.   { m_valid = false; }
  44.  
  45.   bool m_valid;
  46.   bool m_directory;
  47.   bool m_renamed;
  48.   bool m_link;
  49.   KURL m_src;
  50.   KURL m_dst;
  51.   QString m_target;
  52. };
  53.  
  54. struct KonqCommand
  55. {
  56.   typedef QValueStack<KonqCommand> Stack;
  57.  
  58.   enum Type { COPY, MOVE, LINK, MKDIR, TRASH };
  59.  
  60.   KonqCommand()
  61.   { m_valid = false; }
  62.  
  63.   bool m_valid;
  64.  
  65.   Type m_type;
  66.   KonqBasicOperation::Stack m_opStack;
  67.   KURL::List m_src;
  68.   KURL m_dst;
  69. };
  70.  
  71. class KonqCommandRecorder : public QObject
  72. {
  73.   Q_OBJECT
  74. public:
  75.   KonqCommandRecorder( KonqCommand::Type op, const KURL::List &src, const KURL &dst, KIO::Job *job );
  76.   virtual ~KonqCommandRecorder();
  77.  
  78. private slots:
  79.   void slotResult( KIO::Job *job );
  80.  
  81.   void slotCopyingDone( KIO::Job *, const KURL &from, const KURL &to, bool directory, bool renamed );
  82.   void slotCopyingLinkDone( KIO::Job *, const KURL &from, const QString &target, const KURL &to );
  83.  
  84. private:
  85.   class KonqCommandRecorderPrivate;
  86.   KonqCommandRecorderPrivate *d;
  87. };
  88.  
  89. class LIBKONQ_EXPORT KonqUndoManager : public QObject, public DCOPObject
  90. {
  91.   Q_OBJECT
  92.   K_DCOP
  93.   friend class KonqUndoJob;
  94. public:
  95.   enum UndoState { MAKINGDIRS, MOVINGFILES, REMOVINGDIRS, REMOVINGFILES };
  96.  
  97.   KonqUndoManager();
  98.   virtual ~KonqUndoManager();
  99.  
  100.   static void incRef();
  101.   static void decRef();
  102.   static KonqUndoManager *self();
  103.  
  104.   void addCommand( const KonqCommand &cmd );
  105.  
  106.   bool undoAvailable() const;
  107.   QString undoText() const;
  108.  
  109. public slots:
  110.   void undo();
  111.  
  112. signals:
  113.   void undoAvailable( bool avail );
  114.   void undoTextChanged( const QString &text );
  115.  
  116. protected:
  117.   /**
  118.    * @internal
  119.    */
  120.   void stopUndo( bool step );
  121.  
  122. private:
  123. k_dcop:
  124.   virtual ASYNC push( const KonqCommand &cmd );
  125.   virtual ASYNC pop();
  126.   virtual ASYNC lock();
  127.   virtual ASYNC unlock();
  128.  
  129.   virtual KonqCommand::Stack get() const;
  130.  
  131. private slots:
  132.   void slotResult( KIO::Job *job );
  133.  
  134. private:
  135.   void undoStep();
  136.  
  137.   void undoMakingDirectories();
  138.   void undoMovingFiles();
  139.   void undoRemovingFiles();
  140.   void undoRemovingDirectories();
  141.  
  142.   void broadcastPush( const KonqCommand &cmd );
  143.   void broadcastPop();
  144.   void broadcastLock();
  145.   void broadcastUnlock();
  146.  
  147.   void addDirToUpdate( const KURL& url );
  148.   bool initializeFromKDesky();
  149.  
  150.   class KonqUndoManagerPrivate;
  151.   KonqUndoManagerPrivate *d;
  152.   static KonqUndoManager *s_self;
  153.   static unsigned long s_refCnt;
  154. };
  155.  
  156. QDataStream &operator<<( QDataStream &stream, const KonqBasicOperation &op );
  157. QDataStream &operator>>( QDataStream &stream, KonqBasicOperation &op );
  158.  
  159. QDataStream &operator<<( QDataStream &stream, const KonqCommand &cmd );
  160. QDataStream &operator>>( QDataStream &stream, KonqCommand &cmd );
  161.  
  162. #endif
  163.